package com.wandian.util
{

	public class VOUtil
	{
		private static var _I :VOUtil = null;
		public function VOUtil(prv :PrivateClass)
		{
		}
		
		public function str2Ary(str :String):Array
		{
//			//注意文本编码的问题 utf8 无BOM格式，要以二进制的数据传到服务器才行
			var arr :Array = str.split("\n");
			var result :Array = [];
			for each(var item :String in arr)
			{
				if(item == "") continue;
				result.push(item.split("\t"));
			}
			return result;
		}
		
		public function createList(str :String,cls :Class):Array
		{
			var arr :Array = str2Ary(str);
			
			var error :Array = null;
			var list :Array = null;
			if(arr && arr.length > 0)
			{
				//第一组是注释，不要
				arr.shift();
				//属性名
				var propertyAry :Array = arr.shift() as Array;
				list = [];
				for(var i :int = 0; i < arr.length; i++)
				{
					var tempAry :Array = arr[i] as Array;
					var obj :Object = new cls();
					for(var index :int = 0; index < propertyAry.length; index++)
					{
						var name :String = StringUtil.trim(propertyAry[index] as String);
						var value :String = StringUtil.trim(tempAry[index]);
						try
						{
							if(obj.hasOwnProperty(name))
							{
								if(obj[name] is Array)  //数组
								{
									obj[name].push(value);
								}else
								{
									obj[name] = value;
								}
							}else
							{
							}
						}
						catch(e :Error)
						{
							if(!error)
							{
								error = [];
							}
							error.push(name);
						}
					}
					list.push(obj);
					
				}
				
				if(error && error.length > 0)
				{
					trace("没有绑定的属性： " + error);
				}
				
				
				return list;
			}
			return null;
		}
		

		public static function get I():VOUtil
		{
			if(_I == null)
			{
				_I = new VOUtil(new PrivateClass());
			}
			return _I;
		}

	}
}


class PrivateClass{}